package com.insurance.pingan.bid.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class NumberUtils {
	
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
	
	/**
	 * 随机数
	 * @param number 位数
	 * @return
	 */
	public static String randomNumber(int number){
		Random random = new Random();
	    StringBuffer sb = new StringBuffer();
	    for(int i = 0; i < number ; i++){
	    	sb.append(random.nextInt(9)+1);
	    }
	    return sb.toString();
	}
	
	/**
	 * 生成卡片id
	 * @return
	 */
	public static String generateCardID(int number){
	    Random random = new Random();
	    StringBuffer sb = new StringBuffer();
	    sb.append(dateFormat.format(new Date()));
	    for(int i = 0; i < number ; i++){
	    	sb.append(random.nextInt(9)+1);
	    }
	    return sb.toString();
	}
	
	/**
	 * 批量生成卡片id数组
	 * @param cardNumber
	 * @return
	 */
	public static List<String> generateCardIDList(int cardNumber){
		List<String> list = new ArrayList<String>();
		while(list.size() < cardNumber){
			String cardId = generateCardID(8);
			if(!list.contains(cardId)){
				list.add(cardId);
			}
		}
		return list;
	}
	
	
	public static List<String> generateCardIDList(List<String> cardList, int cardNumber){
		List<String> list = new ArrayList<String>();
		while(list.size() < cardNumber){
			String cardId = "NJ"+randomNumber(16);
			if(!cardList.contains(cardId)){
				list.add(cardId);
				cardList.add(cardId);
			}
		}
		return list;
	}
	
}
